package zjh.Servlet;

import java.io.IOException;
import java.sql.SQLException;

import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.apache.commons.dbutils.handlers.MapListHandler;
import org.diyi.Servlet.BaseServlet;
import org.diyi.Tools.BaseDao;
import org.diyi.bean.ResponDate;



@WebServlet("/GetImgServlet")
public class GetImgServlet extends BaseServlet {
	ResponDate data= new ResponDate();

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
	
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setHeader("Content-Type", "text/html;charset=utf-8");
		this.request=request;
		this.response=response;
		Integer imgtype=getInt("imgtype");
		Integer productid=getInt("productid");
		// Integer userid=getInt("userid");
		try {
		if ("select".equals(getString("type"))) {
			System.out.println("select");
			String sql=("select imgid from image where imgtype=? and productid=?");
				List<Map<String, Object>> img1 =BaseDao.query.query(sql, new MapListHandler(),imgtype,productid);
				response.getWriter().write(gson.toJson(img1));
		}
		else if ("selectAll".equals(getString("type"))) {
	     System.out.println("All");
			List<Map<String, Object>> query = BaseDao.query.query("select * from image",new MapListHandler());
		response.getWriter().write(gson.toJson(query));
	}
		
		}catch (SQLException e) {
			e.printStackTrace();
			}
			
	}	
      
}
